<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-header"  style="color:#d02e25;font-family: '楷体'; ">
            组织人员列表
        </div>

        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item refresh-nav" align="center" style="font-family: '宋体'; font-size: 20px;">
                <div class="layui-inline">
                    <label class="layui-form-label">人员名</label>
                    <div class="layui-input-inline">
                        <input style="height: auto;margin-top: 5px" type="text" name="personName" id="personName" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">序号</label>
                    <div class="layui-input-inline">
                        <input style="height: auto;margin-top: 5px" type="text" name="personNum" id="personNum" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" id="searchBtn" data-type="reload">搜索</button>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="personList" lay-filter="personList"></table>
            </div>
        </div>
    </div>

    <script>
        layui.use(['table','form'], function(){
            var table = layui.table
                ,form = layui.form
                ,laydate = layui.laydate;

            //组织人员列表
            table.render({
                elem: '#personList'
                // ,height: 'full-200'
                ,method: 'post'
                ,url: '/ajax/party/admin/personlist'
                ,page: true
                ,loading: true
                ,cellMinWidth: 80
                ,limit: 20
                ,id: 'personList'
                ,cols: [[
                    {field: 'id', title: '序号', width: 80, sort: true, fixed: 'left'}
                    ,{field: 'name', title: '党员姓名 '}
                    ,{field: 'joinDate', title: '入党日期'}
                    ,{field: 'branch', title: '所属组织'}
                    ,{field: 'becomefullDate', title: '转正日期 '}
                    ,{fixed: 'right', title: '操作', align: 'center', width: 120, toolbar: '#dothing' }
                ]]
            });

            //重载，搜索刷新
            layui.$("#searchBtn").click(function () {
                var personNum = $('#personNum').val();//获取输入框的值
                var personName = $("#personName").val();
                if(personNum == null || personNum==""){
                    personNum=0;
                }
                console.log(personNum);
                console.log(personName);

                table.reload('personList',
                    {
                        page:
                            {
                                curr: 1 //重新从第 1 页开始
                            }
                        ,limit:10
                        ,where: { personNum: personNum,
                            personName:personName}//这里传参  向后台
                        ,url: '/ajax/party/admin/serarchPerson'//后台做模糊搜索接口路径
                        ,method: 'post',
                    });

            });




            //监听工具条
            table.on('tool(personList)', function(obj){
                var data = obj.data;

                if(obj.event === 'detail'){

                    $.post('/ajax/party/admin/getOnePerson',{
                        id:data.id
                    },function(result){
                        layer.open({
                            type: 1,
                            area: ['1200px','80%'],
                            title: "ID:" + data.id,
                            offset: '10%',
                            anim: 4,
                            shadeClose: true,
                            content: showDetails(result.data)
                        });
                        // update_form_value(result);
                        console.log(result);
                        var check1 = result.data.work;
                        var check2 = result.data.isOut;
                        var check3= result.data.isFlow;
                        var check4 = result.data.isOutcontact;
                        var check5 = result.data.isTwoRepresents;
                        var check6= result.data.isCollegeOfficial;


                        if(check1=="已退休"){
                            $("#work").attr("checked",true);
                        }

                        if(check2=="是"){
                            $("#isOut").attr("checked",true);
                        }

                        if(check3=="是"){
                            $("#isFlow").attr("checked",true);
                        }
                        if(check4=="是"){
                            $("#isOutcontact").attr("checked",true);
                        }

                        if(check5=="是"){
                            $("#isTwoRepresents").attr("checked",true);
                        }
                        if(check6=="是"){
                            $("#isCollegeOfficial").attr("checked",true);
                        }


                        form.render();
                        // console.log(result.data.time);

                        laydate.render({
                            elem: '#birthday'
                        });

                        laydate.render({
                            elem: '#joinDate'
                        });

                        laydate.render({
                            elem: '#becomefullDate'
                        });
                        form.render();


                        $.post("/ajax/party/admin/branches",{
                            check:1024
                        },function (res) {
                            //得到所有级别
                            //输出
                            console.log(res);
                            var index = 0;
                            res = res.data;
                            for(i = 0; i < res.length; i++){
                                if(res[i].branchName == result.data.branch){
                                    var obj=document.getElementById('branch');
                                    obj.options[obj.options.length]=new Option(res[i].branchName,res[i].branchName);
                                    $("#branch>option").eq(obj.options.length-1).attr("selected", true);
                                    index = obj.options.length-1;
                                }else {
                                    document.getElementById("branch").options.add(new Option(res[i].branchName,res[i].branchName));
                                }
                            }
                            form.render('select');
                        });

                        $.post("/ajax/party/education_degree",{
                            check:1024
                        },function (res) {
                            console.log(res);
                            var index = 0;
                            res = res.data;
                            for(i = 0; i < res.length; i++){
                                if(res[i].name == result.data.education){
                                    var obj=document.getElementById('education');
                                    obj.options[obj.options.length]=new Option(res[i].name,res[i].name);
                                    $("#education>option").eq(obj.options.length-1).attr("selected", true);
                                    index = obj.options.length-1;
                                }else {
                                    document.getElementById("education").options.add(new Option(res[i].name,res[i].name));
                                }
                            }
                            form.render('select');
                        })



                        form.on('submit(ok)',function (data) {

                            //设置id
                            data.field.id = obj.data.id;


                            //将数据转换成是否
                            if(data.field.isOut="on"){
                                data.field.isOut = "是";
                            }else{
                                data.field.isOut = "否";
                            }

                            if(data.field.work="on"){
                                data.field.work = "是";
                            }else{
                                data.field.work = "否";
                            }

                            if(data.field.isFlow="on"){
                                data.field.isFlow = "是";
                            }else{
                                data.field.isFlow = "否";
                            }

                            if(data.field.isOutcontact="on"){
                                data.field.isOutcontact = "是";
                            }else{
                                data.field.isOutcontact = "否";
                            }

                            if(data.field.isTwoRepresents="on"){
                                data.field.isTwoRepresents = "是";
                            }else{
                                data.field.isTwoRepresents = "否";
                            }

                            if(data.field.isCollegeOfficial="on"){
                                data.field.isCollegeOfficial = "是";
                            }else{
                                data.field.isCollegeOfficial = "否";
                            }

                            console.log(data.field);
                            $.ajax({
                                type:"post",
                                url:"/ajax/party/admin/addperson",
                                contentType : 'application/json;charset=utf-8',
                                //设置请求头信息
                                dataType:"json",
                                data:JSON.stringify(data.field),
                                success:function (res) {
                                    if(res.code==0){
                                        layer.alert("OK");
                                    }else {
                                        layer.alert("发生了一些小错误，提交失败！");
                                    }
                                }
                            })
                            return false;

                        })
                    });

                }
                else if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        $.post("/ajax/party/admin/delPerson",{
                            id:data.id
                        },function(result){
                            console.log(result);
                            if(result.code==0){
                                layer.alert("删除成功！");
                            }
                            obj.del();
                            layer.close(index);
                        });
                    });
                }
            });



            function showDetails(data) {
                var s = '<form class="layui-form" id="form1">\n' +
                    '        <div class="layui-card">\n' +
                    '            <div class="layui-card-header"  style="color:#d02e25;font-family: \'楷体\'; ">\n' +
                    '                添加组织人员\n' +
                    '            </div>\n' +
                    '            <div class="layui-card-body">\n' +
                    '                <div class="layui-card-header"  style="color:#d02e25;font-family: \'楷体\'; ">\n' +
                    '                    基本人员信息\n' +
                    '                </div>\n' +
                    '                <div class="layui-form-item">\n' +
                    '                    <label class="layui-form-label">姓名</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="name" value='+ data.name +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">性别</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="sex" value='+ data.sex +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">民族</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="nation" value='+ data.nation +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">出生年月</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="born" id="birthday" value='+ data.born +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">身份证号</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="idCard" value='+ data.idCard +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">籍贯</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="hrResiter" value='+ data.hrResiter +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">学历</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <div class="layui-inline" style="width: 100%;">\n' +
                    '                            <div class="layui-input-inline" style="width: 100%;">\n' +
                    '                                <select name="education" id="education"  lay-verify="required" lay-search="" style="width: 100%;">\n' +
                    '\n' +
                    '                                </select>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">婚姻状况</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="marriage" value='+ data.marriage +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <input type="checkbox" name="work" id="work" title="是否退休">\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">家庭住址</label>\n' +
                    '                    <div class="layui-input-inline" style="width: 35%;">\n' +
                    '                        <input type="text" name="livein" value='+ data.livein +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">手机号码&nbsp;</label>\n' +
                    '                    <div class="layui-input-inline" >\n' +
                    '                        <input type="text" name="telephone" value='+ data.telephone +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">毕业院校</label>\n' +
                    '                    <div class="layui-input-inline" >\n' +
                    '                        <input type="text" name="school" value='+ data.school +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">所学专业&nbsp;</label>\n' +
                    '                    <div class="layui-input-inline"  >\n' +
                    '                        <input type="text" name="major" value='+ data.major +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">电子邮箱</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="email" value='+ data.email+'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">QQ</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="qq"  value='+ data.qq +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">微信</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="weixin"  value='+ data.weixin +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-card-header"  style="color:#d02e25;font-family: \'楷体\'; ">\n' +
                    '                    党籍信息\n' +
                    '                </div>\n' +
                    '                <div class="layui-form-item">\n' +
                    '                    <label class="layui-form-label">入党日期</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="joinDate" value='+ data.joinDate +' id="joinDate" lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">固定电话</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="ptelephone" value='+ data.ptelephone +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">头像位置</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="personalPhoto" value='+ data.personalPhoto+' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">所在党支部</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <div class="layui-inline" style="width: 100%;">\n' +
                    '                            <div class="layui-input-inline" style="width: 100%;">\n' +
                    '                                <select name="branch" id="branch" lay-verify="required" lay-search="" style="width: 100%;">\n' +
                    '\n' +
                    '                                </select>\n' +
                    '                            </div>\n' +
                    '                        </div>\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">人员类别</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="personCategory"  value='+ data.personCategory +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">党内职务</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="positionInparty" value='+ data.positionInparty +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">转为正式党员日期</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="becomefullDate" value='+ data.becomefullDate +' id="becomefullDate" lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">党费缴纳基数</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="partyMoney" value='+ data.partyMoney +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">党籍状态</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="membershipStatus"  value='+ data.membershipStatus +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '                <div class="layui-form-item">\n' +
                    '                    <label class="layui-form-label">&nbsp;</label>\n' +
                    '                    <div class="layui-input-block">\n' +
                    '                        <input type="checkbox" name="isOut" id="isOut" title="是否长期在外党员">\n' +
                    '                        <input type="checkbox" name="isFlow" id="isFlow" title="是否流动党员">\n' +
                    '                        <input type="checkbox" name="isOutcontact" id="isOutcontact" title="是否失联党员">\n' +
                    '                        <input type="checkbox" name="isCollegeOfficial" id="isCollegeOfficial" title="是否大学生村官">\n' +
                    '                        <input type="checkbox" name="isTwoRepresents" id="isTwoRepresents" title="是否两代表一委员">\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item layui-form-text">\n' +
                    '                    <label class="layui-form-label">工作岗位</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="workplace" value='+ data.workplace +' lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '                    <label class="layui-form-label">工作职称</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="technicalTitle" value='+ data.technicalTitle +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '\n' +
                    '                    <label class="layui-form-label">行政职务</label>\n' +
                    '                    <div class="layui-input-inline">\n' +
                    '                        <input type="text" name="administrativePosition" value='+ data.administrativePosition +'  lay-verify="required"\n' +
                    '                               autocomplete="off" class="layui-input">\n' +
                    '                    </div>\n' +
                    '\n' +
                    '\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '\n' +
                    '                <div class="layui-form-item" style="margin-left: 440px;">\n' +
                    '                    <div class="layui-input-block">\n' +
                    '                        <button class="layui-btn" lay-submit lay-filter="ok">提交</button>\n' +
                    '                        <button type="reset" class="layui-btn layui-btn-primary" id="reset">重置</button>\n' +
                    '                    </div>\n' +
                    '                </div>\n' +
                    '\n' +
                    '\n' +
                    '            </div>\n' +
                    '        </div>\n' +
                    '    </form>';
                return s;

            }






        });
    </script>

    <script type="text/html" id="dothing">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>

        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script type="text/html" id="cropUrlShow">
        <img src="/static/upload/{{d.cropUrlShow}}" style="height:48px;width:48px;line-height:48px!important;"/>
    </script>
</div>